function refreshHeader(flag, t) {
   // 获取蛋糕系列列表
   $.get('/typeList', function (types) {
      if (types != null && types.length != 0) {
         types.forEach(function (type) {
            var oldHtml = document.getElementById('typeList').innerHTML;
            var newHtml = oldHtml + `<li><a className="list" href="/goods_list?typeid=${type.id}">${type.name}</a></li>`;
            document.getElementById('typeList').innerHTML = newHtml;
         });
      }
   }, 'json');

   // 获取当前购物车里的订单（数量一个，包含多个蛋糕列表）
   $.get('/order', function (order) {
      if (order != null)
         document.getElementById('orderAmount').innerText = order.amount;
      else
         document.getElementById('orderAmount').innerText = 0;
   });

   // 获取当前登录用户
   $.get('/user', function (user) {
      if (user != null) {
         document.getElementById('registerUser').style.display = 'none';
         document.getElementById('login').style.display = 'none';
         if (user.isadmin == false)
            document.getElementById('adminIndex').style.display = 'none';
      } else {
         document.getElementById('orderList').style.display = 'none';
         document.getElementById('userCenter').style.display = 'none';
         document.getElementById('logout').style.display = 'none';
         document.getElementById('adminIndex').style.display = 'none';
      }
   });

   // 控制导航栏的可见性
   var navlinks = document.querySelectorAll(".navbar-nav > li > a");
   for (let i = 0; i < navlinks.length; i++) {
      const link = navlinks[i];
      if (link.innerText == '首页' && flag == 1)
         link.classList.add("active");
      else if (link.innerText == '商品分类' && flag == 2)
         link.classList.add("active");
      else if (link.innerText == '热销' && flag == 3 && t == 2)
         link.classList.add("active");
      else if (link.innerText == '新品' && flag == 3 && t == 3)
         link.classList.add("active");
      else if (link.innerText == '注册' && flag == 10)
         link.classList.add("active");
      else if (link.innerText == '登录' && flag == 9)
         link.classList.add("active");
      else if (link.innerText == '我的订单' && flag == 5)
         link.classList.add("active");
      else if (link.innerText == '个人中心' && flag == 4)
         link.classList.add("active");
   }
   if (flag == 7)
      document.getElementById("submit").classList.add('active');
   if (flag == 8)
      document.getElementById("cart").classList.add('active');
}
